from dash import html
import dash_bootstrap_components as dbc
import base64
import os

# 读取图片并转换为base64
image_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 
                         "static", "icon", "leftup_logo.png")
encoded_image = ""
try:
    with open(image_path, 'rb') as f:
        encoded_image = base64.b64encode(f.read()).decode('ascii')
    print(f"图片加载成功: {image_path}")
    print(f"Base64编码长度: {len(encoded_image)}")
except Exception as e:
    print(f"无法加载图片: {str(e)}")
    print(f"尝试加载的路径: {image_path}")

management_menu = dbc.DropdownMenu(
    label="管理操作",  # 或者使用一个图标
    children=[
        dbc.DropdownMenuItem("修改密码", href="#"), # href 可以链接到相应页面，或通过 n_clicks 触发回调
        dbc.DropdownMenuItem("新建用户", href="#"),
        dbc.DropdownMenuItem("停用用户", href="#"),
    ],
    nav=True,
    in_navbar=True,
    align_end=True, # 通常让菜单在右侧对齐
    color="primary", # 或者其他您希望的颜色
    className="ml-2" # 根据需要调整边距
)

# 导航栏组件
navbar = dbc.Navbar(
    dbc.Container(
        [
            # 添加图标和品牌名称
            html.A(
                dbc.Row(
                    [
                        # 使用assets文件夹中的图片
                        dbc.Col(html.Img(src="/assets/icon/leftup_logo.png", height="40px"), width="auto"),
                        dbc.Col(dbc.NavbarBrand("设备资产信息管理系统", className="ms-2")),
                                          
                       
                    ],
                    align="center",
                    className="g-0",
                ),
                href="/dash/",
                style={"textDecoration": "none"},
            ),
            # 导航链接
            dbc.NavbarToggler(id="navbar-toggler"),
            dbc.Collapse(
                dbc.Nav(
                    [
                        dbc.NavItem(dbc.NavLink("设备台账", href="http://localhost:5000/dash/equipment", external_link=True, target="_blank")),
                        dbc.NavItem(dbc.NavLink("维修记录", href="/dash/maintenance", target="_blank")),
                        dbc.NavItem(dbc.NavLink("数据分析", href="/dash/dashboard", target="_blank")),
                        dbc.NavItem(dbc.NavLink("系统设置", href="/dash/settings", target="_blank")),
                    ],
                    className="ms-auto",
                    navbar=True,
                ),
                id="navbar-collapse",
                navbar=True,
            ),
        ],
        fluid=True,
    ),
    color="#0d47a1",
    dark=True,
    className="mb-4",
)